package com.example.gybicycle.common.util;

import com.example.gybicycle.common.enums.NumType;
import com.example.gybicycle.entity.MemberDeposit;
import com.example.gybicycle.entity.MemberInsure;
import com.example.gybicycle.entity.MemberOrder;
import com.example.gybicycle.entity.SysUser;
import com.example.gybicycle.entity.wx.OpenLock;
import com.example.gybicycle.entity.wx.WXLoginInfo;
import org.springframework.beans.BeanUtils;

import java.math.BigDecimal;
import java.util.Date;

public class CyclingUtil {

    public static MemberOrder createOrder(OpenLock lock,String bikeId,String loginId,String point){
        MemberOrder order=new MemberOrder();
        order.setBikeId(bikeId);
        order.setStartTime(new Date());
        order.setOrderState(0);
        order.setPriceType(lock.getPriceType());
        order.setStartPoint(point);
        order.setMemberId(loginId);
        order.setPayState(3);
        return order;
    }

    public static MemberDeposit createDeposit(String orderId,String loginId){
        MemberDeposit deposit=new MemberDeposit();
        deposit.setMemberId(loginId);
        deposit.setMemberOrderId(orderId);
        deposit.setDepositState(0);
        deposit.setPayTime(new Date());
        deposit.setMoney(new BigDecimal(0.01));
        deposit.setId(NumberUtil.getNum(NumType.DEPOSIT));
        return deposit;
    }
    public static MemberInsure createInsure(OpenLock openLock,String loginId){
        MemberInsure insure=new MemberInsure();
        BeanUtils.copyProperties(openLock,insure);
        insure.setStartTime(new Date());
        insure.setInsureId(1);
        return insure;
    }

    public static void setWxLoginInfo(SysUser user,WXLoginInfo info){
        info.setId(user.getId());
        info.setType(1);
        info.setName(user.getNickName());
        info.setTelphone(user.getTelphone());
        info.setWxOpenid(user.getWxNo());
        info.setAuthorization("eqweqwej"+user.getWxNo());
    }

    public static String cyclingPath(){
        return "[{\"title\":\"骑行租车\",\"click\":\"CLICK IT>\",\"icon\":\"cycling.png\",\"path\":\"/pages/maps/index\",\"class\":\"cycling\"}" +
               "]";
//        return "[{\"title\":\"骑行租车\",\"click\":\"CLICK IT>\",\"icon\":\"cycling.png\",\"path\":\"/pages/maps/index\",\"class\":\"cycling\"}," +
//                "{\"title\":\"咖啡、软饮\",\"click\":\"CLICK IT>\",\"icon\":\"coffee.png\",\"path\":\"\",\"class\":\"coffee\"}," +
//                "{\"title\":\"团建服务\",\"click\":\"CLICK IT>\",\"icon\":\"serve.png\",\"path\":\"\",\"class\":\"serve\"}," +
//                "{\"title\":\"VIP会员\",\"click\":\"CLICK IT>\",\"icon\":\"vip.png\",\"path\":\"\",\"class\":\"vip\"}]";
    }
    public static String AdminPath(){

        return " [ { \"title\":\"扫码开锁\"," +
                "\"click\":\"CLICK IT>\"," +
                "\"icon\":\"scancode.png\"," +
                "\"path\":\"\"," +
                "\"class\":\"open\"," +
                "\"state\":\"1\"" +
                "}," +
                "{" +
                "\"title\":\"扫码关锁\"," +
                "\"click\":\"CLICK IT>\"," +
                "\"icon\":\"scancode.png\"," +
                "\"path\":\"\"," +
                "\"class\":\"close\"," +
                "\"state\":\"2\"" +
                "}," +
                "{" +
                "\"title\":\"故障处理\"," +
                "\"click\":\"CLICK IT>\"," +
                "\"icon\":\"failure_white.png\"," +
                "\"path\":\"/pages/troubleShooting\"," +
                "\"class\":\"troubleShooting\"" +
                "}]";
    }

    public static String setOrderState(MemberOrder order){
//         @Schema(description = "订单状态 0 进行中 1已完成 2 已报修 3 押金已支付3")
//    private Integer orderState;
//    @Schema(description = "支付状态  0 未支付  1 已支付 2 支付失败  ")
        switch (order.getOrderState()){
            case 0:
                return "骑行中";
            case 1:
                switch (order.getPayState()){
                    case 0:
                        return "待支付";
                    case 1:
                        return  "已完成";
                    case 2:
                        return "支付失败";
                }
            case 2:
                return "已报修";
            case 3:
                return "已付押金";
        }
        return "";
    }
    public static Integer setOrderStateByMy(MemberOrder order){

        switch (order.getOrderState()){
            case 0: case 2:
                return 3;
            case 1:
                switch (order.getPayState()){
                    case 0:case 2:
                        return 2;
                    case 1:
                        return  4;
                }
        }

        return 3;
    }
}
